package com.hehanpeng.springbootthread;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author hehanpeng
 * @date 2018/9/14 14:03
 */
//@Component
public class ScheduledTask {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Autowired
    AsyncService asyncService;

    //@Scheduled(fixedDelayString = "${jobs.fixedDelay}")
//    @Scheduled(fixedDelayString = "2000")
    public void getTask1() {
        System.out.println("任务1,从配置文件加载任务信息，当前时间：" + dateFormat.format(new Date()));
    }

//    @Scheduled(cron = "${jobs.cron}")
    @Scheduled(cron = "0/5 * * * * ?")
    public void getTask2() {
        System.out.println("任务2,从配置文件加载任务信息，当前时间：" + dateFormat.format(new Date()));
        asyncService.executeAsync(0);
    }
}
